home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Libraries / glut / glut_shapes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  14.0 KB  |  638 lines  |  [TEXT/CWIE]

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /**
  5. (c) Copyright 1993, Silicon Graphics, Inc.
  6.  
  7. ALL RIGHTS RESERVED
  8.  
  9. Permission to use, copy, modify, and distribute this software
  10. for any purpose and without fee is hereby granted, provided
  11. that the above copyright notice appear in all copies and that
  12. both the copyright notice and this permission notice appear in
  13. supporting documentation, and that the name of Silicon
  14. Graphics, Inc. not be used in advertising or publicity
  15. pertaining to distribution of the software without specific,
  16. written prior permission.
  17.  
  18. THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU
  19. "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR
  20. OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  21. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  IN NO
  22. EVENT SHALL SILICON GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE
  23. ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR
  24. CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER,
  25. INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE,
  26. SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR
  27. NOT SILICON GRAPHICS, INC.  HAS BEEN ADVISED OF THE POSSIBILITY
  28. OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE OR
  30. PERFORMANCE OF THIS SOFTWARE.
  31.  
  32. US Government Users Restricted Rights
  33.  
  34. Use, duplication, or disclosure by the Government is subject to
  35. restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  36. (c)(1)(ii) of the Rights in Technical Data and Computer
  37. Software clause at DFARS 252.227-7013 and/or in similar or
  38. successor clauses in the FAR or the DOD or NASA FAR
  39. Supplement.  Unpublished-- rights reserved under the copyright
  40. laws of the United States.  Contractor/manufacturer is Silicon
  41. Graphics, Inc., 2011 N.  Shoreline Blvd., Mountain View, CA
  42. 94039-7311.
  43.  
  44. OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  45. */
  46.  
  47. #include <math.h>
  48. #include "gl.h"
  49. #include "glu.h"
  50. #include "glut.h"
  51. #include "glutint.h"
  52.  
  53. static GLUquadricObj *quadObj;
  54.  
  55. #define QUAD_OBJ_INIT() { if(!quadObj) initQuadObj(); }
  56.  
  57. #define M_PI      3.14159265359
  58.  
  59. static void
  60. initQuadObj(void)
  61. {
  62.   quadObj = gluNewQuadric();
  63.   if (!quadObj)
  64.     __glutFatalError("out of memory.");
  65. }
  66.  
  67. /* CENTRY */
  68. void
  69. glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
  70. {
  71.   QUAD_OBJ_INIT();
  72.   gluQuadricDrawStyle(quadObj, GLU_LINE);
  73.   gluQuadricNormals(quadObj, GLU_SMOOTH);
  74.   /* If we ever changed/used the texture or orientation state
  75.      of quadObj, we'd need to change it to the defaults here
  76.      with gluQuadricTexture and/or gluQuadricOrientation. */
  77.   gluSphere(quadObj, radius, slices, stacks);
  78. }
  79.  
  80. void
  81. glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
  82. {
  83.   QUAD_OBJ_INIT();
  84.   gluQuadricDrawStyle(quadObj, GLU_FILL);
  85.   gluQuadricNormals(quadObj, GLU_SMOOTH);
  86.   /* If we ever changed/used the texture or orientation state
  87.      of quadObj, we'd need to change it to the defaults here
  88.      with gluQuadricTexture and/or gluQuadricOrientation. */
  89.   gluSphere(quadObj, radius, slices, stacks);
  90. }
  91.  
  92. void
  93. glutWireCone(GLdouble base, GLdouble height,
  94.   GLint slices, GLint stacks)
  95. {
  96.   QUAD_OBJ_INIT();
  97.   gluQuadricDrawStyle(quadObj, GLU_LINE);
  98.   gluQuadricNormals(quadObj, GLU_SMOOTH);
  99.   /* If we ever changed/used the texture or orientation state
  100.      of quadObj, we'd need to change it to the defaults here
  101.      with gluQuadricTexture and/or gluQuadricOrientation. */
  102.   gluCylinder(quadObj, base, 0.0, height, slices, stacks);
  103. }
  104.  
  105. void
  106. glutSolidCone(GLdouble base, GLdouble height,
  107.   GLint slices, GLint stacks)
  108. {
  109.   QUAD_OBJ_INIT();
  110.   gluQuadricDrawStyle(quadObj, GLU_FILL);
  111.   gluQuadricNormals(quadObj, GLU_SMOOTH);
  112.   /* If we ever changed/used the texture or orientation state
  113.      of quadObj, we'd need to change it to the defaults here
  114.      with gluQuadricTexture and/or gluQuadricOrientation. */
  115.   gluCylinder(quadObj, base, 0.0, height, slices, stacks);
  116. }
  117.  
  118. /* ENDCENTRY */
  119.  
  120. static void
  121. drawBox(GLfloat x0, GLfloat x1, GLfloat y0, GLfloat y1,
  122.   GLfloat z0, GLfloat z1, GLenum type)
  123. {
  124.   static GLfloat n[6][3] =
  125.   {
  126.     {-1.0, 0.0, 0.0},
  127.     {0.0, 1.0, 0.0},
  128.     {1.0, 0.0, 0.0},
  129.     {0.0, -1.0, 0.0},
  130.     {0.0, 0.0, 1.0},
  131.     {0.0, 0.0, -1.0}
  132.   };
  133.   static GLint faces[6][4] =
  134.   {
  135.     {0, 1, 2, 3},
  136.     {3, 2, 6, 7},
  137.     {7, 6, 5, 4},
  138.     {4, 5, 1, 0},
  139.     {5, 6, 2, 1},
  140.     {7, 4, 0, 3}
  141.   };
  142.   GLfloat v[8][3], tmp;
  143.   GLint i;
  144.  
  145.   if (x0 > x1) {
  146.     tmp = x0;
  147.     x0 = x1;
  148.     x1 = tmp;
  149.   }
  150.   if (y0 > y1) {
  151.     tmp = y0;
  152.     y0 = y1;
  153.     y1 = tmp;
  154.   }
  155.   if (z0 > z1) {
  156.     tmp = z0;
  157.     z0 = z1;
  158.     z1 = tmp;
  159.   }
  160.   v[0][0] = v[1][0] = v[2][0] = v[3][0] = x0;
  161.   v[4][0] = v[5][0] = v[6][0] = v[7][0] = x1;
  162.   v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0;
  163.   v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1;
  164.   v[0][2] = v[3][2] = v[4][2] = v[7][2] = z0;
  165.   v[1][2] = v[2][2] = v[5][2] = v[6][2] = z1;
  166.  
  167.   for (i = 0; i < 6; i++) {
  168.     glBegin(type);
  169.     glNormal3fv(&n[i][0]);
  170.     glVertex3fv(&v[faces[i][0]][0]);
  171.     glVertex3fv(&v[faces[i][1]][0]);
  172.     glVertex3fv(&v[faces[i][2]][0]);
  173.     glVertex3fv(&v[faces[i][3]][0]);
  174.     glEnd();
  175.   }
  176. }
  177.  
  178. /* CENTRY */
  179. void
  180. glutWireCube(GLdouble size)
  181. {
  182.   drawBox(-size / 2., size / 2.,
  183.     -size / 2., size / 2.,
  184.     -size / 2., size / 2.,
  185.     GL_LINE_LOOP);
  186. }
  187.  
  188. void
  189. glutSolidCube(GLdouble size)
  190. {
  191.   drawBox(-size / 2., size / 2.,
  192.     -size / 2., size / 2.,
  193.     -size / 2., size / 2.,
  194.     GL_QUADS);
  195. }
  196.  
  197. /* ENDCENTRY */
  198.  
  199. static void
  200. doughnut(GLfloat r, GLfloat R, GLint nsides,
  201.   GLint rings, GLenum type)
  202. {
  203.   int i, j;
  204.   GLfloat theta, phi, theta1, phi1;
  205.   GLfloat p0[03], p1[3], p2[3], p3[3];
  206.   GLfloat n0[3], n1[3], n2[3], n3[3];
  207.  
  208.   for (i = 0; i < rings; i++) {
  209.     theta = (GLfloat) i *2.0 * M_PI / rings;
  210.     theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
  211.     for (j = 0; j < nsides; j++) {
  212.       phi = (GLfloat) j *2.0 * M_PI / nsides;
  213.       phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
  214.  
  215.       p0[0] = cos(theta) * (R + r * cos(phi));
  216.       p0[1] = -sin(theta) * (R + r * cos(phi));
  217.       p0[2] = r * sin(phi);
  218.  
  219.       p1[0] = cos(theta1) * (R + r * cos(phi));
  220.       p1[1] = -sin(theta1) * (R + r * cos(phi));
  221.       p1[2] = r * sin(phi);
  222.  
  223.       p2[0] = cos(theta1) * (R + r * cos(phi1));
  224.       p2[1] = -sin(theta1) * (R + r * cos(phi1));
  225.       p2[2] = r * sin(phi1);
  226.  
  227.       p3[0] = cos(theta) * (R + r * cos(phi1));
  228.       p3[1] = -sin(theta) * (R + r * cos(phi1));
  229.       p3[2] = r * sin(phi1);
  230.  
  231.       n0[0] = cos(theta) * (cos(phi));
  232.       n0[1] = -sin(theta) * (cos(phi));
  233.       n0[2] = sin(phi);
  234.  
  235.       n1[0] = cos(theta1) * (cos(phi));
  236.       n1[1] = -sin(theta1) * (cos(phi));
  237.       n1[2] = sin(phi);
  238.  
  239.       n2[0] = cos(theta1) * (cos(phi1));
  240.       n2[1] = -sin(theta1) * (cos(phi1));
  241.       n2[2] = sin(phi1);
  242.  
  243.       n3[0] = cos(theta) * (cos(phi1));
  244.       n3[1] = -sin(theta) * (cos(phi1));
  245.       n3[2] = sin(phi1);
  246.  
  247.       glBegin(type);
  248.       glNormal3fv(n3);
  249.       glVertex3fv(p3);
  250.       glNormal3fv(n2);
  251.       glVertex3fv(p2);
  252.       glNormal3fv(n1);
  253.       glVertex3fv(p1);
  254.       glNormal3fv(n0);
  255.       glVertex3fv(p0);
  256.       glEnd();
  257.     }
  258.   }
  259. }
  260.  
  261. /* CENTRY */
  262. void
  263. glutWireTorus(GLdouble innerRadius, GLdouble outerRadius,
  264.   GLint nsides, GLint rings)
  265. {
  266.   doughnut(innerRadius, outerRadius,
  267.     nsides, rings, GL_LINE_LOOP);
  268. }
  269.  
  270. void
  271. glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius,
  272.   GLint nsides, GLint rings)
  273. {
  274.   doughnut(innerRadius, outerRadius, nsides, rings, GL_QUADS);
  275. }
  276.  
  277. /* ENDCENTRY */
  278.  
  279. static GLfloat dodec[20][3];
  280.  
  281. static void
  282. initDodecahedron(void)
  283. {
  284.   GLfloat alpha, beta;
  285.  
  286.   alpha = sqrt(2.0 / (3.0 + sqrt(5.0)));
  287.   beta = 1.0 + sqrt(6.0 / (3.0 + sqrt(5.0)) -
  288.     2.0 + 2.0 * sqrt(2.0 / (3.0 + sqrt(5.0))));
  289.   /* *INDENT-OFF* */
  290.   dodec[0][0] = -alpha; dodec[0][1] = 0; dodec[0][2] = beta;
  291.   dodec[1][0] = alpha; dodec[1][1] = 0; dodec[1][2] = beta;
  292.   dodec[2][0] = -1; dodec[2][1] = -1; dodec[2][2] = -1;
  293.   dodec[3][0] = -1; dodec[3][1] = -1; dodec[3][2] = 1;
  294.   dodec[4][0] = -1; dodec[4][1] = 1; dodec[4][2] = -1;
  295.   dodec[5][0] = -1; dodec[5][1] = 1; dodec[5][2] = 1;
  296.   dodec[6][0] = 1; dodec[6][1] = -1; dodec[6][2] = -1;
  297.   dodec[7][0] = 1; dodec[7][1] = -1; dodec[7][2] = 1;
  298.   dodec[8][0] = 1; dodec[8][1] = 1; dodec[8][2] = -1;
  299.   dodec[9][0] = 1; dodec[9][1] = 1; dodec[9][2] = 1;
  300.   dodec[10][0] = beta; dodec[10][1] = alpha; dodec[10][2] = 0;
  301.   dodec[11][0] = beta; dodec[11][1] = -alpha; dodec[11][2] = 0;
  302.   dodec[12][0] = -beta; dodec[12][1] = alpha; dodec[12][2] = 0;
  303.   dodec[13][0] = -beta; dodec[13][1] = -alpha; dodec[13][2] = 0;
  304.   dodec[14][0] = -alpha; dodec[14][1] = 0; dodec[14][2] = -beta;
  305.   dodec[15][0] = alpha; dodec[15][1] = 0; dodec[15][2] = -beta;
  306.   dodec[16][0] = 0; dodec[16][1] = beta; dodec[16][2] = alpha;
  307.   dodec[17][0] = 0; dodec[17][1] = beta; dodec[17][2] = -alpha;
  308.   dodec[18][0] = 0; dodec[18][1] = -beta; dodec[18][2] = alpha;
  309.   dodec[19][0] = 0; dodec[19][1] = -beta; dodec[19][2] = -alpha;
  310.   /* *INDENT-ON* */
  311.  
  312. }
  313.  
  314. #define DIFF3(_a,_b,_c) { \
  315.     (_c)[0] = (_a)[0] - (_b)[0]; \
  316.     (_c)[1] = (_a)[1] - (_b)[1]; \
  317.     (_c)[2] = (_a)[2] - (_b)[2]; \
  318. }
  319.  
  320. static void
  321. crossprod(GLfloat v1[3], GLfloat v2[3], GLfloat prod[3])
  322. {
  323.   GLfloat p[3];        /* in case prod == v1 or v2 */
  324.  
  325.   p[0] = v1[1] * v2[2] - v2[1] * v1[2];
  326.   p[1] = v1[2] * v2[0] - v2[2] * v1[0];
  327.   p[2] = v1[0] * v2[1] - v2[0] * v1[1];
  328.   prod[0] = p[0];
  329.   prod[1] = p[1];
  330.   prod[2] = p[2];
  331. }
  332.  
  333. static void
  334. normalize(GLfloat v[3])
  335. {
  336.   GLfloat d;
  337.  
  338.   d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  339.   if (d == 0.0) {
  340.     __glutWarning("normalize: zero length vector");
  341.     v[0] = d = 1.0;
  342.   }
  343.   d = 1 / d;
  344.   v[0] *= d;
  345.   v[1] *= d;
  346.   v[2] *= d;
  347. }
  348.  
  349. static void
  350. pentagon(int a, int b, int c, int d, int e, GLenum shadeType)
  351. {
  352.   GLfloat n0[3], d1[3], d2[3];
  353.  
  354.   DIFF3(dodec[a], dodec[b], d1);
  355.   DIFF3(dodec[b], dodec[c], d2);
  356.   crossprod(d1, d2, n0);
  357.   normalize(n0);
  358.  
  359.   glBegin(shadeType);
  360.   glNormal3fv(n0);
  361.   glVertex3fv(&dodec[a][0]);
  362.   glVertex3fv(&dodec[b][0]);
  363.   glVertex3fv(&dodec[c][0]);
  364.   glVertex3fv(&dodec[d][0]);
  365.   glVertex3fv(&dodec[e][0]);
  366.   glEnd();
  367. }
  368.  
  369. static void
  370. dodecahedron(GLenum type)
  371. {
  372.   static int inited = 0;
  373.  
  374.   if (inited == 0) {
  375.     inited = 1;
  376.     initDodecahedron();
  377.   }
  378.   pentagon(0, 1, 9, 16, 5, type);
  379.   pentagon(1, 0, 3, 18, 7, type);
  380.   pentagon(1, 7, 11, 10, 9, type);
  381.   pentagon(11, 7, 18, 19, 6, type);
  382.   pentagon(8, 17, 16, 9, 10, type);
  383.   pentagon(2, 14, 15, 6, 19, type);
  384.   pentagon(2, 13, 12, 4, 14, type);
  385.   pentagon(2, 19, 18, 3, 13, type);
  386.   pentagon(3, 0, 5, 12, 13, type);
  387.   pentagon(6, 15, 8, 10, 11, type);
  388.   pentagon(4, 17, 8, 15, 14, type);
  389.   pentagon(4, 12, 5, 16, 17, type);
  390. }
  391.  
  392. /* CENTRY */
  393. void
  394. glutWireDodecahedron(void)
  395. {
  396.   dodecahedron(GL_LINE_LOOP);
  397. }
  398.  
  399. void
  400. glutSolidDodecahedron(void)
  401. {
  402.   dodecahedron(GL_TRIANGLE_FAN);
  403. }
  404.  
  405. /* ENDCENTRY */
  406.  
  407. static void
  408. recorditem(GLfloat * n1, GLfloat * n2, GLfloat * n3,
  409.   GLenum shadeType)
  410. {
  411.   GLfloat q0[3], q1[3];
  412.  
  413.   DIFF3(n1, n2, q0);
  414.   DIFF3(n2, n3, q1);
  415.   crossprod(q0, q1, q1);
  416.   normalize(q1);
  417.  
  418.   glBegin(shadeType);
  419.   glNormal3fv(q1);
  420.   glVertex3fv(n1);
  421.   glVertex3fv(n2);
  422.   glVertex3fv(n3);
  423.   glEnd();
  424. }
  425.  
  426. static void
  427. subdivide(GLfloat * v0, GLfloat * v1, GLfloat * v2,
  428.   GLenum shadeType)
  429. {
  430.   int depth;
  431.   GLfloat w0[3], w1[3], w2[3];
  432.   GLfloat l;
  433.   int i, j, k, n;
  434.  
  435.   depth = 1;
  436.   for (i = 0; i < depth; i++) {
  437.     for (j = 0; i + j < depth; j++) {
  438.       k = depth - i - j;
  439.       for (n = 0; n < 3; n++) {
  440.         w0[n] = (i * v0[n] + j * v1[n] + k * v2[n]) / depth;
  441.         w1[n] = ((i + 1) * v0[n] + j * v1[n] + (k - 1) * v2[n])
  442.           / depth;
  443.         w2[n] = (i * v0[n] + (j + 1) * v1[n] + (k - 1) * v2[n])
  444.           / depth;
  445.       }
  446.       l = sqrt(w0[0] * w0[0] + w0[1] * w0[1] + w0[2] * w0[2]);
  447.       w0[0] /= l;
  448.       w0[1] /= l;
  449.       w0[2] /= l;
  450.       l = sqrt(w1[0] * w1[0] + w1[1] * w1[1] + w1[2] * w1[2]);
  451.       w1[0] /= l;
  452.       w1[1] /= l;
  453.       w1[2] /= l;
  454.       l = sqrt(w2[0] * w2[0] + w2[1] * w2[1] + w2[2] * w2[2]);
  455.       w2[0] /= l;
  456.       w2[1] /= l;
  457.       w2[2] /= l;
  458.       recorditem(w1, w0, w2, shadeType);
  459.     }
  460.   }
  461. }
  462.  
  463. static void
  464. drawtriangle(int i, GLfloat data[][3], int ndx[][3],
  465.   GLenum shadeType)
  466. {
  467.   GLfloat *x0, *x1, *x2;
  468.  
  469.   x0 = data[ndx[i][0]];
  470.   x1 = data[ndx[i][1]];
  471.   x2 = data[ndx[i][2]];
  472.   subdivide(x0, x1, x2, shadeType);
  473. }
  474.  
  475. /* octahedron data: The octahedron produced is centered at the
  476.    origin and has radius 1.0 */
  477. static GLfloat odata[6][3] =
  478. {
  479.   {1.0, 0.0, 0.0},
  480.   {-1.0, 0.0, 0.0},
  481.   {0.0, 1.0, 0.0},
  482.   {0.0, -1.0, 0.0},
  483.   {0.0, 0.0, 1.0},
  484.   {0.0, 0.0, -1.0}
  485. };
  486.  
  487. static int ondex[8][3] =
  488. {
  489.   {0, 4, 2},
  490.   {1, 2, 4},
  491.   {0, 3, 4},
  492.   {1, 4, 3},
  493.   {0, 2, 5},
  494.   {1, 5, 2},
  495.   {0, 5, 3},
  496.   {1, 3, 5}
  497. };
  498.  
  499. static void
  500. octahedron(GLenum shadeType)
  501. {
  502.   int i;
  503.  
  504.   for (i = 0; i < 8; i++) {
  505.     drawtriangle(i, odata, ondex, shadeType);
  506.   }
  507. }
  508.  
  509. /* CENTRY */
  510. void
  511. glutWireOctahedron(void)
  512. {
  513.   octahedron(GL_LINE_LOOP);
  514. }
  515.  
  516. void
  517. glutSolidOctahedron(void)
  518. {
  519.   octahedron(GL_TRIANGLES);
  520. }
  521.  
  522. /* ENDCENTRY */
  523.  
  524. /* icosahedron data: These numbers are rigged to make an
  525.    icosahedron of radius 1.0 */
  526.  
  527. #define X .525731112119133606
  528. #define Z .850650808352039932
  529.  
  530. static GLfloat idata[12][3] =
  531. {
  532.   {-X, 0, Z},
  533.   {X, 0, Z},
  534.   {-X, 0, -Z},
  535.   {X, 0, -Z},
  536.   {0, Z, X},
  537.   {0, Z, -X},
  538.   {0, -Z, X},
  539.   {0, -Z, -X},
  540.   {Z, X, 0},
  541.   {-Z, X, 0},
  542.   {Z, -X, 0},
  543.   {-Z, -X, 0}
  544. };
  545.  
  546. static int index[20][3] =
  547. {
  548.   {0, 4, 1},
  549.   {0, 9, 4},
  550.   {9, 5, 4},
  551.   {4, 5, 8},
  552.   {4, 8, 1},
  553.   {8, 10, 1},
  554.   {8, 3, 10},
  555.   {5, 3, 8},
  556.   {5, 2, 3},
  557.   {2, 7, 3},
  558.   {7, 10, 3},
  559.   {7, 6, 10},
  560.   {7, 11, 6},
  561.   {11, 0, 6},
  562.   {0, 1, 6},
  563.   {6, 1, 10},
  564.   {9, 0, 11},
  565.   {9, 11, 2},
  566.   {9, 2, 5},
  567.   {7, 2, 11},
  568. };
  569.  
  570. static void
  571. icosahedron(GLenum shadeType)
  572. {
  573.   int i;
  574.  
  575.   for (i = 0; i < 20; i++) {
  576.     drawtriangle(i, idata, index, shadeType);
  577.   }
  578. }
  579.  
  580. /* CENTRY */
  581. void
  582. glutWireIcosahedron(void)
  583. {
  584.   icosahedron(GL_LINE_LOOP);
  585. }
  586.  
  587. void
  588. glutSolidIcosahedron(void)
  589. {
  590.   icosahedron(GL_TRIANGLES);
  591. }
  592.  
  593. /* ENDCENTRY */
  594.  
  595. /* tetrahedron data: */
  596.  
  597. #define T       1.73205080756887729
  598.  
  599. static GLfloat tdata[4][3] =
  600. {
  601.   {T, T, T},
  602.   {T, -T, -T},
  603.   {-T, T, -T},
  604.   {-T, -T, T}
  605. };
  606.  
  607. static int tndex[4][3] =
  608. {
  609.   {0, 1, 3},
  610.   {2, 1, 0},
  611.   {3, 2, 0},
  612.   {1, 2, 3}
  613. };
  614.  
  615. static void
  616. tetrahedron(GLenum shadeType)
  617. {
  618.   int i;
  619.  
  620.   for (i = 0; i < 4; i++)
  621.     drawtriangle(i, tdata, tndex, shadeType);
  622. }
  623.  
  624. /* CENTRY */
  625. void
  626. glutWireTetrahedron(void)
  627. {
  628.   tetrahedron(GL_LINE_LOOP);
  629. }
  630.  
  631. void
  632. glutSolidTetrahedron(void)
  633. {
  634.   tetrahedron(GL_TRIANGLES);
  635. }
  636.  
  637. /* ENDCENTRY */
  638.